// src/main/java/com/nb/vo/DeptDetailVO.java
package com.nb.vo;

import com.nb.entity.Dept;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 部门详情VO（包含父部门信息）
 */
@Data
public class DeptDetailVO {
    // 部门自身信息
    private Long id;
    private String name;
    private Long parentId;
    private String level;
    private Integer sort;
    private String createdBy;
    private String updatedBy;
    private LocalDateTime createdTime;
    private LocalDateTime updatedTime;

    // 父部门信息（仅包含关键字段）
    private ParentDept parentDept;

    /**
     * 父部门简易信息
     */
    @Data
    public static class ParentDept {
        private Long id;
        private String name;
        private String level;
    }

    /**
     * 从Dept实体转换为VO
     */
    public static DeptDetailVO fromDept(Dept dept) {
        DeptDetailVO vo = new DeptDetailVO();
        vo.setId(dept.getId());
        vo.setName(dept.getName());
        vo.setParentId(dept.getParentId());
        vo.setLevel(dept.getLevel());
        vo.setSort(dept.getSort());
        vo.setCreatedBy(dept.getCreatedBy());
        vo.setUpdatedBy(dept.getUpdatedBy());
        vo.setCreatedTime(dept.getCreatedTime());
        vo.setUpdatedTime(dept.getUpdatedTime());
        return vo;
    }

    /**
     * 设置父部门信息
     */
    public void setParentDept(Dept parentDept) {
        if (parentDept == null) {
            this.parentDept = null;
            return;
        }
        ParentDept parent = new ParentDept();
        parent.setId(parentDept.getId());
        parent.setName(parentDept.getName());
        parent.setLevel(parentDept.getLevel());
        this.parentDept = parent;
    }
}